package com.zr.daoimpl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.zr.dao.InsertEIRDao;
import com.zr.model.Ccarreport;
import com.zr.model.Cdriver;
import com.zr.model.Corder;
import com.zr.model.Creceipt;
import com.zr.model.Csealing;
/**
 * lxg
 * @author Administrator
 *
 * @param <T>
 */
@Repository("inEIRdaim")
public class InsertEIRDaoImpl<T> extends BaseDaoImpl<T> implements InsertEIRDao<T>{

	@Override
	public Corder findCorderByOid(int oid) {
		System.out.println(7);
		Corder corder=(Corder) this.getCurrentSession().get(Corder.class, Integer.valueOf(oid));
		System.out.println(corder);
		return corder;
	}

	@Override
	public void findEir(int seid, int oid, String restartp, String reendp, int crid, int did) {
	
		ApplicationContext ac=new ClassPathXmlApplicationContext("bean.xml");  
	        Creceipt cc=(Creceipt) ac.getBean("creceipt"); 
	        
	       // Csealing cs=(Csealing) ac.getBean("csealing");
	        System.out.println(8);
	       // cs.setSeid(seid);
	      //  cc.setCsealing(cs);
	        String hql="from Csealing as cs where cs.seid=:seid";
	        Query query=this.getCurrentSession().createQuery(hql);
	        query.setInteger("seid", seid);
	        Csealing cs=(Csealing) query.uniqueResult();
	        cc.setCsealing(cs);
	        System.out.println(9);
//	        Corder co=(Corder) ac.getBean("corder");
//	        co.setOid(oid);	        
//	        cc.setCorder(co);
	        String hql1="from Corder as co where co.oid=:oid";
	        Query query1=this.getCurrentSession().createQuery(hql1);
	        query1.setInteger("oid", oid);
	        Corder co=(Corder) query1.uniqueResult();
	        cc.setCorder(co);
	        System.out.println(10);
	        cc.setRestartp(restartp);
	        cc.setReendp(reendp);
	        System.out.println(11);
//	        Ccarreport ccp=(Ccarreport) ac.getBean("ccarreport");
//	        ccp.setCrid(crid);
//	        cc.setCcarreport(ccp);
	        String hql2="from Ccarreport as cc where cc.ccarinfo.cid=crid";
	        Query query2=this.getCurrentSession().createQuery(hql2);
	       // query2.setInteger("cid", crid);
	        Ccarreport ccp=(Ccarreport) query2.uniqueResult();
	        cc.setCcarreport(ccp);
	      //  System.out.println(cc.getCcarreport().getCcarinfo().getCid());
	        System.out.println(12);
//	        Cdriver cd=(Cdriver) ac.getBean("cdriver");
//	        cd.setDid(did);
//	        cc.setCdriver(cd);
	        String hql3="from Cdriver as cd where cd.did=:did";
	        Query query3=this.getCurrentSession().createQuery(hql3);
	        query3.setInteger("did", did);
	        Cdriver cd=(Cdriver) query3.uniqueResult();
	        cc.setCdriver(cd);
	        System.out.println(13);
	        this.getCurrentSession().save(cc);
	      
	}

}
